package tests.app;

import org.apache.zookeeper.ZooKeeper;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import qq2564874169.tuaotuao.fx.app.FxSpringApp;
import qq2564874169.tuaotuao.fx.app.WebApplicationContext;
import qq2564874169.tuaotuao.fx.app.ro.ROContext;
import qq2564874169.tuaotuao.fx.app.ro.ZkHostProvider;

@SpringBootApplication
public class App extends FxSpringApp {
    public static void main(String[] args) {
        var app = new App();
        app.isContextWithRequest = true;
        app.run(args);
    }

    @Override
    protected Integer getPort() {
        return 8899;
    }

    @Override
    protected void appStartup(WebApplicationContext context, ApplicationArguments args) {
        super.appStartup(context, args);
        var zk = context.getBean(ZooKeeper.class);
        ZkHostProvider.createRootNode(zk);
        var host = new ZkHostProvider(zk, "http://localhost:" + getPort());
        ROContext.remoteProviders.add(host);
        ROContext.addHandler(TestHandle.class);
        ROContext.start(this);
    }
}
